/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-07-26
 * Time: 20:43
 * To BE A Better Person-2020-3-2
 */
public class TestDemo {
    //针对同一个对象加锁
    public static Object locker1=new Object();
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            synchronized (locker1){
                System.out.println("t1 start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 end");
            }

        });
        Thread t2=new Thread(()->{
            synchronized (locker1){
                System.out.println("t2 start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2 end");
            }

        });
        t1.start();
        t2.start();
    }
}
